package com.liaoyifan.core.converter;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

@SuppressWarnings("unused")
public class ConverterList {

    private static <S, T> T of(S source, Function<S, T> converter) {
        if (source == null) return null;
        return converter.apply(source);
    }

    public static <S, T> List<T> of(List<S> sourceList, Function<S, T> converter) {
        if (sourceList == null) return null;

        List<T> result = new ArrayList<>(sourceList.size());
        for (S source : sourceList) {
            result.add(of(source, converter));
        }
        return result;
    }
}
